﻿using Abp.Runtime.Session;
using Abp.Timing.Timezone;
using Camc.Quality.DataExporting.Excel.EpPlus;
using Camc.Quality.Dto;
using Camc.Quality.Storage;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Camc.Quality.BomContrastive.BomContrastiveInterface
{
   public class BomContrastiveToExcel : EpPlusExcelExporterBase, IBomContrastiveToExcel
    {
        private readonly ITimeZoneConverter _timeZoneConverter;
        private readonly IAbpSession _abpSession;
   
        public BomContrastiveToExcel(
            ITimeZoneConverter timeZoneConverter,
           // IAbpSession abpSession,
            ITempFileCacheManager tempFileCacheManager)
            : base(tempFileCacheManager)
        {
            _timeZoneConverter = timeZoneConverter;
           // _abpSession = abpSession;
        }
        public string ExportToFile(List<BomAnalysisDto>  bomAnalysisDtos)
        {
            return CreateExcelPackageLocal(
                "设计bom比对分析详细内容.xlsx",
                excelPackage =>
                {
                    var sheet = excelPackage.Workbook.Worksheets.Add(L("分析对比"));
                    sheet.OutLineApplyStyle = true;

                    AddHeader(
                        sheet,
                        L("物料代码"),
                        L("物料名称"),
                        L("规格型号"),
                        L("物料属性"),
                        L("物料类别"),
                        L("单位"),
                        L("设计bom用量"),
                        L("制造bom用量"),
                        L("对比差异")
                        );

                    AddObjects(
                        sheet, 2, bomAnalysisDtos,
                        _ => _.MaterialNo,
                        _ => _.MaterialName,
                        _ => _.Model,
                        _ => _.MaterialProperty,
                        _ => _.MaterialTypeName,
                        _ => _.Unit,
                        _ => _.Unit1BomDosage,
                        _ => _.Unit1BomMake,
                        _ => _.Difference
                        );
                    //Formatting cells
                    var creationTimeColumn = sheet.Column(11);
                    creationTimeColumn.Style.Numberformat.Format = "yyyy-mm-dd HH:mm:ss";

                    for (var i = 1; i <= 9; i++)
                    {
                        sheet.Column(i).AutoFit();
                    }
                });
        }
    }
}
